package com.mm.dao;

import com.mm.pojo.User;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
 * @author XiaoLuo
 * @ClassName: UserDao
 * @Description: ${todo}
 * @date 2019/4/6 20:56
 */
/*@Component
public class UserDao {
	@Autowired
	private RestTemplate restTemplate;


	private static final Logger LOGGER= LoggerFactory.getLogger(UserDao.class);

	@HystrixCommand(fallbackMethod = "queryUserByIdFallback")
	public User queryUserById(Long id){
		long start = System.currentTimeMillis();
		//之前根据discoverClient来请求的  ，此时换成了restTemplate直接请求
		//因为有了Ribbon的加持  所以他自己可以负载均衡
		String url = "http://user-service/user/"+id;
		User user = this.restTemplate.getForObject(url, User.class);
		long end = System.currentTimeMillis();

		//记录时间
		LOGGER.info("id为：{} 的访问时间：{}",id,end-start);
		return user;
	}
	public User queryUserByIdFallback(Long id){
		User user = new User();
		user.setId(id);
		user.setName("用户查询异常");
		return user;
	}


}*/
